
package question_answer;
import edu.stanford.nlp.trees.*;
import edu.stanford.nlp.parser.lexparser.LexicalizedParser;
import java.util.*;

public class Parser {

    //String STR_COLECTTION_WORD;// list result form stanford parser: STR_COLECTION_WORD
    public Parser()
    {
       // this.STR_COLECTTION_WORD = "";
    }
   
    public String MakeParser(String rSentence)
    {
        // slip string input
        int index_end = rSentence.length();
        String temp = rSentence.substring(index_end-1);
        rSentence = rSentence.substring(0, index_end-1);
        String[] rlistWord = rSentence.split(" ");
        String[] listWord = new String[rlistWord.length +1];
        for(int i = 0; i <rlistWord.length;i++)
            listWord[i] = rlistWord[i];
        listWord[listWord.length-1] = temp;
        listWord[0] = listWord[0].toLowerCase();
        //----------------
        LexicalizedParser lp = new LexicalizedParser("englishPCFG.ser");
        lp.setOptionFlags(new String[]{"-maxLength", "80", "-retainTmpSubcategories"});
        Tree parse = (Tree) lp.apply(Arrays.asList(rlistWord));
        //parse.pennPrint();

        TreebankLanguagePack tlp = new PennTreebankLanguagePack();
        GrammaticalStructureFactory gsf = tlp.grammaticalStructureFactory();
        GrammaticalStructure gs = gsf.newGrammaticalStructure(parse);
        Collection tdl = gs.typedDependencies();
        return tdl.toString();
    }
    
}
